#include "referee.h"

#include <string.h>

/* 根据裁判系统串口协议附录V1.6.1编写 详细查询官网附录 */

referee_data_t referee_data; //比赛状态数据

/**
 * 裁判系统数据解析
 * @param cmd_id 指令ID
 * @param data 数据指针
 * @param data_length 数据长度 
 */
void referee_parsed(uint16_t cmd_id, uint8_t* data, uint16_t data_length)
{
    switch (cmd_id)
    {
        case REFEREE_CMD_ID_GAME_STATUS:    //比赛状态
            memcpy(&referee_data.game_status, data, data_length);
            break;

        case REFEREE_CMD_ID_GAME_RESULT:    //比赛结果
            memcpy(&referee_data.game_result, data, data_length);
            break;

        case REFEREE_CMD_ID_GAME_ROBOT_HP:  //机器人血量数据
            memcpy(&referee_data.game_robot_HP, data, data_length);
            break;

        case REFEREE_CMD_ID_GAME_EVENT_DATA:    //场地事件数据
            memcpy(&referee_data.event_data, data, data_length);
            break;

        case REFEREE_CMD_ID_GAME_EXT_SUPPLY_PROJECTILE_ACTION:  //补给站动作表示
            memcpy(&referee_data.ext_supply_projectile_action, data, data_length);
            break;

        case REFEREE_CMD_ID_REFEREE_WARNING:   //裁判警告数据
            memcpy(&referee_data.referee_warning, data, data_length);
            break;
        
        case REFEREE_CMD_ID_DART_INFO:  //飞镖发射相关数据
            memcpy(&referee_data.dart_info, data, data_length);
            break;
        
        case REFEREE_CMD_ID_ROBOT_STATUS:   //机器人性能体系
            memcpy(&referee_data.robot_status, data, data_length);
            break;

        case REFEREE_CMD_ID_POWER_HEAT_DATA:    //实时底盘功率和枪口热量数据
            memcpy(&referee_data.power_heat_data,data,data_length);
            break;

        case REFEREE_CMD_ID_ROBOT_POS:  //机器人位置数据
            memcpy(&referee_data.robot_pos, data, data_length);
            break;

        case REFEREE_CMD_ID_BUFF:   //机器人增益数据
            memcpy(&referee_data.buff, data, data_length);
            break;

        case REFEREE_CMD_ID_AIR_SUPPORT_DATA:   //空中支援事件数据
            memcpy(&referee_data.air_support_data, data, data_length);
            break;

        case REFEREE_CMD_ID_HURT_DATA:  //伤害状态数据
            memcpy(&referee_data.hurt_data, data, data_length);
            break;

        case REFEREE_CMD_ID_SHOOT_DATA: //实时射击数据
            memcpy(&referee_data.shoot_data, data, data_length);
            break;

        case REFEREE_CMD_ID_PROJIECTILE_ALLOWANCE:  //允许发弹量数据
            memcpy(&referee_data.projectile_allowance, data, data_length);
            break;

        case REFEREE_CMD_ID_RFID_STATUS:    //机器人RFID模块状态
            memcpy(&referee_data.rfid_status, data, data_length);
            break;
        
        case REFEREE_CMD_ID_DART_CLIENT_CMD:    //飞镖选手端数据
            memcpy(&referee_data.dart_client_cmd, data, data_length);
            break;

        case REFEREE_CMD_ID_GROUND_ROBOT_POSITION:  //地面机器人位置数据
            memcpy(&referee_data.ground_robot_position, data, data_length);
            break;   

        case REFEREE_CMD_ID_RADAR_MARK_DATA:    //雷达标记进度数据
            memcpy(&referee_data.radar_mark_data, data, data_length);
            break;

        case REFEREE_CMD_ID_SENTRY_INFO:    //哨兵自主决策信息同步
            memcpy(&referee_data.sentry_info, data, data_length);
            break; 
        
        case REFEREE_CMD_ID_RADAR_INFO: //雷达自主决策信息同步
            memcpy(&referee_data.radar_info, data, data_length);
            break; 
        
        default:
            break;
    }
}

/*
    获取裁判系统数据的函数建议写法：
    void get_xxxx()
    {
        
    }
*/

//获取当前底盘功率和剩余能量缓冲
void get_chassis_power_and_buffer(fp32* chassis_power, fp32* chassis_power_buffer)
{
    *chassis_power = referee_data.power_heat_data.chassis_power;            //获得当前底盘功率
    *chassis_power_buffer = referee_data.power_heat_data.buffer_energy;     //获得当前底盘缓冲能量
}

//获取当前最大底盘功率限制
void get_chassis_max_power(uint16_t* max_power_limit)
{
    *max_power_limit = referee_data.robot_status.chassis_power_limit;  //获取当前底盘最大功率
}
